/**
 * Created by Lee on 2021/7/10.
 * Comments:
*/

#include "Card_wr.h"

void ReadCard(uint8 block, uint8 addr, int times)
{
    int soc = UHF900M();
    int i=0;
    times=10;
    while(i<times)
    {
        printf("Read Card:\n");
        if(Inventory () == 0 )
        {
            InventoryStop();

            sleep(1);

            if(ReadBuf(block,addr,1)==0) printf("Read Successful.\n");

            sleep(2);
        }
        i++;
    }
    Cclose(soc);
}

void ReadCard_server(uint8 block, uint8 addr)
{
    int soc = UHF900M();

    while(1)
    {
        printf("Read Card:\n");
        if(Inventory () == 0 )
        {
            InventoryStop();

            sleep(1);

            if(ReadBuf(block,addr,1)==0) printf("Read Successful.\n");

            sleep(1);
        }
    }
    Cclose(soc);
}

void WriteCard(uint8 block, uint8 addr, uint8 value1, uint8 value2, int times)
{
    int soc = UHF900M();
    int i=0;
    times=10;

    uint8 str[2] ={value1,value2};
    while(i<times)
    {
        printf("Write Card:\n");
        if(Inventory () == 0 )
        {
            InventoryStop();
            //reserve store
            if(WriteBuf(block,0x00,str,1)==0) printf("Write Successfull.\n");
            sleep(1);
            if(ReadBuf(block,0x00,1)==0) printf("write Successful.\n");
            sleep(1);
        }
        i++;
    }
    Cclose(soc);
}

void WriteCard_server(uint8 block, uint8 addr, uint8 value1, uint8 value2)
{
    int soc = UHF900M();

    uint8 str[2] ={value1,value2};
    while(1)
    {
        printf("Write Card:\n");
        if(Inventory () == 0 )
        {
            InventoryStop();
            //reserve store
            if(WriteBuf(block,addr,str,1)==0) printf("Write Successfull.\n");
            sleep(1);
            if(ReadBuf(block,addr,1)==0) printf("write Successful.\n");
            sleep(1);
        }
    }
    Cclose(soc);
}
